package simple.utils.tracking.storage;

import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.serializers.AbstractSerializer;

import java.nio.ByteBuffer;

/**
 * Created by martin on 14.5.14.
 */
public class CassandraByteArraySerializer extends AbstractSerializer<CassandraByteArrayKey> implements Serializer<CassandraByteArrayKey> {

    @Override
    public ByteBuffer toByteBuffer(CassandraByteArrayKey cbk) {
        ByteBuffer wrap = ByteBuffer.wrap(cbk.getKey());
        return wrap;
    }

    @Override
    public CassandraByteArrayKey fromByteBuffer(ByteBuffer bb) {
        ByteBuffer dup = bb.duplicate();
        byte[] bytes = new byte[dup.remaining()];
        bb.get(bytes, 0, bytes.length);
        return new CassandraByteArrayKey(bytes);
    }
}
